package com.hu.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 图片url 虚拟地址解析
 *
 * @author ZhouKai
 * 2022/4/19 18:16
 */
@Configuration
public class UrlConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //获取文件的真实路径
        String imgPath = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
        String cssPath = System.getProperty("user.dir") + "\\src\\main\\resources\\templates\\css\\";
        String jsPath = System.getProperty("user.dir") + "\\src\\main\\resources\\templates\\js\\";
        //uploadFile对应resource下工程目录
        registry.addResourceHandler("/images/**").addResourceLocations("file:" + imgPath);
        registry.addResourceHandler("/css/**").addResourceLocations("file:" + cssPath);
        registry.addResourceHandler("/js/**").addResourceLocations("file:" + jsPath);
    }
}
